<template>
  <div style="width:50%;">
    <el-dialog :visible.sync="modelVisible">
    <el-form ref="form" :model="modelTemp" label-width="80px"  >
      <el-form-item label="标题">
        <el-input v-model="modelTemp.title"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="modelTemp.tid" placeholder="请选择">
          <el-option
              v-for="item in typeList"
              :key="item.id"
              :label="item.vtype"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="来源">
        <el-select v-model="modelTemp.sid" placeholder="请选择">
          <el-option
              v-for="item in sourceList"
              :key="item.id"
              :label="item.vsource"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="简单描述">
        <el-input v-model="modelTemp.simpleDes"></el-input>
      </el-form-item>
      <el-form-item label="日期">
          <el-date-picker type="date" placeholder="选择日期" v-model="modelTemp.date" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="modelTemp.des"></el-input>
      </el-form-item>
      <el-form-item label="播放源">
        <el-input v-model="modelTemp.sourceUrl"></el-input>
      </el-form-item>
      <el-form-item label="图片源">
        <el-input v-model="modelTemp.imgUrl"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleOk" v-show="method==='add'">新增</el-button>
        <el-button type="primary" @click="handleOk" v-show="method==='edit'">更新</el-button>
        <el-button @click="modelVisible=false">取消</el-button>
      </el-form-item>
    </el-form>
    </el-dialog>
  </div>

</template>

<script>
import {addVideo,editVideo} from "@/plugins/api";

export default {
  name: "Modal",
  data(){
    return{
      modelTemp:{},
      modelVisible:false,
      method:"",
      typeList:[
        {
          id:1,
          vtype:"综艺",
        },
        {
          id:2,
          vtype:"电影",
        },
        {
          id:3,
          vtype:"记录片",
        },
        {
          id:4,
          vtype:"音乐",
        },

      ],
      sourceList:[
        {
          id:1,
          vsource:"爱奇艺",
        },
        {
          id:2,
          vsource:"腾讯",
        },
        {
          id:3,
          vsource:"优酷",
        },
        {
          id:4,
          vsource:"b站",
        },

      ]

    }
  },
  methods:{
    edit(record){
      this.modelTemp=Object.assign({}, record);
    },
    add(){
       this.edit();
    },
    handleOk() {
      var _this=this;
      if (this.method === 'add'){
        addVideo(this.modelTemp).then(function (msg){
          if(msg.code==200){
            _this.$emit("ok");
            _this.modelVisible=false;
            _this.$message.success(msg.msg);
          }else{
            _this.$message.warning(msg.msg);
          }
        })
      }
      else if(this.method === 'edit'){
        editVideo(this.modelTemp).then(function (msg){
           if(msg.code==200){
             _this.$emit("ok");
             _this.modelVisible=false;
             _this.$message.success(msg.msg);
           }else{
             _this.$message.warning(msg.msg);
           }
        })
      }
    },
    close () {
      this.$refs.form.clearValidate();
      this.$refs.form.resetFields();
      this.$emit("close");
      this.modelVisible= false;
    },
  }
}
</script>

<style scoped>

</style>